package view.formatters;

import java.util.List;

import model.Speaker;
import model.SpeakerRole;
import tools.Translator;
import view.ResultFormatter;
import algo.DistributionResult.SingleDebateDistribution;

import com.google.inject.Inject;

public class OPDResultFormatter implements ResultFormatter {

	private final Translator tr;
	private final SpeakerRole firstGov;
	private final SpeakerRole secondGov;
	private final SpeakerRole thirdGov;
	private final SpeakerRole firstOp;
	private final SpeakerRole secondOp;
	private final SpeakerRole thirdOp;
	private final SpeakerRole ffr;

	@Inject
	public OPDResultFormatter(Translator tr, SpeakerRole firstGov, SpeakerRole secondGov, SpeakerRole thirdGov, SpeakerRole firstOp,
			SpeakerRole secondOp, SpeakerRole thirdOp, SpeakerRole ffr) {
		this.tr = tr;
		this.firstGov = firstGov;
		this.secondGov = secondGov;
		this.thirdGov = thirdGov;
		this.firstOp = firstOp;
		this.secondOp = secondOp;
		this.thirdOp = thirdOp;
		this.ffr = ffr;
	}

	@Override
	public String getFormattedResult(SingleDebateDistribution dist) {
		StringBuilder text = new StringBuilder();

		text.append("<table style='font-size:1.1em' border='0'><tr><th colspan=\"2\">");
//		text.append(dist.getRoom());
		text.append("Raum");
		text.append("</th></tr><tr><td><b>" + tr.tr(firstGov.getLabel()) + "</b><br>");
		text.append(dist.getFirstSpeakerForRole(firstGov)
				.getName());
		text.append("</td><td><b>" + tr.tr(firstOp.getLabel()) + "</b><br>");
		text.append(dist.getFirstSpeakerForRole(firstOp).getName());
		text.append("</td></tr><tr><td><b>" + tr.tr(secondGov.getLabel()) + "</b><br>");
		text.append(dist.getFirstSpeakerForRole(secondGov)
				.getName());
		text.append("</td><td><b>" + tr.tr(secondOp.getLabel()) + "</b><br>");
		text.append(dist.getFirstSpeakerForRole(secondOp)
				.getName());
		text.append("</td></tr><tr><td><b>" + tr.tr(thirdGov.getLabel()) + "</b><br>");
		text.append(dist.getFirstSpeakerForRole(thirdGov)
				.getName());
		text.append("</td><td><b>" + tr.tr(thirdOp.getLabel()) + "</b><br>");
		text.append(dist.getFirstSpeakerForRole(thirdOp).getName());
		text.append("</td></tr>");

		List<Speaker> ffrs = dist.getSpeakersForRole(ffr);
		if (ffrs.size() > 0) {
			text.append("<tr><td colspan=\"2\"><b>Freie Redner:</b><br>");
			text.append(ffrs.get(0).getName());

			for (int i = 1; i < ffrs.size(); i++) {
				text.append(", ");
				text.append(ffrs.get(i).getName());
			}
			text.append("</td></tr>");

		}
		text.append("</table>");

		return text.toString();
	}

}
